import { useEffect } from "react";
import { AppState, AppStateStatus } from "react-native";

type OnActive = () => void

const useActiveEffect = (onActive: OnActive) => {
  useEffect(() => {
    const handleAppStateChange = (nextAppState: AppStateStatus) => {
      if (nextAppState === "active") {
        onActive();
      }
    };
    AppState.addEventListener("change", handleAppStateChange);
  }, [onActive]);
};

export default useActiveEffect;
